<template>
  <rx-dialog @handOk="cancel" :oktext="$ti18('rxForm.closeBtn','关闭')" order="bottom" :showcancel="false">
    <div v-if="currentName=='edit1'" slot="toolbar">

      <a-button type="primary" @click="onNext">{{i18n('list.next','下一步')}}</a-button>
    </div>
    <div v-if="currentName=='edit2'" slot="toolbar">
        <a-button type="primary" @click="onBefore">{{i18n('list.resTemplate','重新选择模板')}}</a-button>
      <a-button type="primary" @click="onSave">{{$ti18('rxForm.saveBtn','保存')}}</a-button>
    </div>
    <rx-layout>
      <div slot="center">
        <component ref="current" :is="currentView" :pkId="pkId":boDefId="boDefId" :templates="templates" :layerid="layerid" :destroy="destroy"></component>
      </div>
    </rx-layout>

  </rx-dialog>
</template>
<script>

  import {Util, RxDialog} from "@lowcode/jpaas-common-lib";
  import FormPcPdfTemp1 from "./FormPcPdfTemp1";
  import FormPcPdfTemp2 from "./FormPcPdfTemp2";
  export default {
   /* props:["record","layerid","destroy"],*/
    props:["pkId","layerid","destroy","formId","formName","boDefId","allowEdit"],
    components: {
      RxDialog,
      FormPcPdfTemp1,
      FormPcPdfTemp2
    },
    data(){
      return {
        templates:'',
        currentName:'edit1',
        edit1:FormPcPdfTemp1,
        edit2:FormPcPdfTemp2,
        currentView:FormPcPdfTemp1
      }
    },
    created() {
      if(this.pkId){
        this.currentName='edit2';
        this.currentView=this.edit2;
      }

    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"pdfTemplate",key);
      },
      cancel(){
        Util.closeWindow(this,"cancel");
      },
      onSave(e){
        this.currentView.methods.handleSubmit(this,this.$refs.current,e);
      },
      onNext(){
        var boConfig=this.currentView.methods.getBoConfig(this.$refs.current);
        this.boDefId=boConfig.boDefId;
        this.templates=boConfig.templates;
        this.currentName='edit2';
        this.currentView=this.edit2;
      },
      onBefore(){
        this.currentView=this.edit1;
        this.currentName="edit1";
        this.oktext=this.$ti18('rxForm.saveBtn','保存');
      },

    }
  }
</script>
<style>
  .footerToolBar button{
    margin-right: 6px;
  }
</style>
